package com.test.test01.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.test.test01.bean.SystemJob;
import com.test.test01.common.request.bo.ImmediatelyExecuteBO;
import com.test.test01.common.request.bo.PageSystemJobBO;
import com.test.test01.common.request.bo.SystemJobStatusBO;
import com.test.test01.service.SystemJobService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class SystemJobController {

    @Resource
    private SystemJobService systemJobService;

    /**
     * 添加系统定时任务
     */
    @GetMapping(value = "addSystemJob")
    public Object addSystemJob(@RequestBody SystemJob systemJob) {
        systemJobService.addSystemJob(systemJob);
        return "success";
    }

    /**
     * 分页查询系统定时任务
     */
    @GetMapping(value = "pageSystemJob")
    public Object pageSystemJob(@RequestBody PageSystemJobBO bo) {
        Page<SystemJob> systemJobPage = systemJobService.pageSystemJob(bo.getBeanName(), bo.getMethodName(),
                bo.getJobStatus(), bo.getPageNo(), bo.getPageSize());
        return systemJobPage;
    }

    /**
     * 修改系统定时任务
     */
    @GetMapping(value = "modifySystemJob")
    public Object modifySystemJob(@RequestBody SystemJob systemJob) {
         systemJobService.modifySystemJob(systemJob);
        return "success";
    }

    /**
     * 移除系统定时任务
     */
    @GetMapping(value = "removeSystemJob")
    public Object removeSystemJob(@RequestBody Long id) {
        systemJobService.removeSystemJob(id);
        return "success";
    }

    /**
     * 修改定时任务状态
     */
    @GetMapping(value = "modifyJobStatus")
    public Object modifyJobStatus(@RequestBody SystemJobStatusBO bo){
        systemJobService.modifyJobStatus(bo.getId(),bo.getJobStatus());
        return "success";
    }

    /**
     * 获取定时任务详情
     */
    @GetMapping(value = "querySystemJob")
    public Object querySystemJob(@RequestBody Long id){
        SystemJob systemJob = systemJobService.querySystemJob(id);
        return systemJob;
    }

    /**
     * 立即执行
     */
    @GetMapping(value = "immediatelyExecute")
    public Object immediatelyExecute(@RequestBody ImmediatelyExecuteBO bo){
        systemJobService.immediatelyExecute(bo.getBeanName(),bo.getMethodName(),bo.getMethodParams());
        return "success";
    }
}


